package com.blood.core.config.file;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.MultipartConfigElement;

/**
 * @author yelong
 * @version 1.0
 * @date 2020/8/24 11:48
 * @description
 */
@Configuration
public class FileClientConfig implements WebMvcConfigurer {
    /**
     * 配置上传文件的目录
     */
    @Value("${file.uploadFolder}")
    private String uploadFolder;
    @Value("${file.staticAccessPath}")
    private String staticAccessPath;

    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setLocation(uploadFolder);
        return factory.createMultipartConfig();
    }


    public void addReturnValueHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler(staticAccessPath).addResourceLocations(uploadFolder);
    }
}
